# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=itstool
pkgver=2.0.4
pkgrel=2
pkgdesc="XML to PO and back again"
arch=('i686' 'x86_64')
url="http://itstool.org/"
license=("GPL3")
depends=("python2" "libxml2" "libxml2-python")
source=(http://files.itstool.org/itstool/${pkgname}-${pkgver}.tar.bz2
        fix-segfault.patch)
sha256sums=('97c208b51da33e0b553e830b92655f8deb9132f8fbe9a646771f95c33226eb60'
            'ccdf85ae9bdfd0259728a79b6b9806d8b9bcb27ed1f974ac49c551587cb4e6c6')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/fix-segfault.patch
  sed -i '1s|#!/usr/bin/python|&2|' itstool itstool.in
  sed -i 's/| python/&2/' configure.ac
  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${CHOST}"
  cd "${srcdir}/build-${CHOST}"
    PYTHON=/usr/bin/python2 \
    ../${pkgname}-${pkgver}/configure \
    --prefix=/usr \
    --build=${CHOST} \
    --host=${CHOST} \
    --target=${CHOST}
    make
}

check() {
  cd build-${CHOST}
  make -k check
}

package() {
  cd "${srcdir}/build-${CHOST}"
  make DESTDIR="${pkgdir}" install
  sed -e "s|/usr/bin/python |/usr/bin/python2 |g" -i ${pkgdir}/usr/bin/itstool
}
